#!/usr/bin/make -f

PACKAGE_NAME := g3proxy
BUILD_PROFILE := release-lto

DEB_VERSION ?= $(shell dpkg-parsechangelog -SVersion)
LUA_FEATURE ?= $(shell scripts/package/detect_lua_feature.sh)
SSL_FEATURE ?= $(shell scripts/package/detect_openssl_feature.sh)
CARES_FEATURE ?= $(shell scripts/package/detect_c-ares_feature.sh)

%:
	dh $@

override_dh_clean:
	dh_clean -Xvendor

override_dh_auto_clean:
	cargo clean --frozen --offline

override_dh_auto_build:
	G3_PACKAGE_VERSION=$(DEB_VERSION) \
	  cargo build --frozen --profile $(BUILD_PROFILE) \
	    --no-default-features --features $(LUA_FEATURE),$(SSL_FEATURE),rustls-ring,quic,$(CARES_FEATURE) \
	    --package g3proxy --package g3proxy-ctl --package g3proxy-lua
	cargo build --frozen --profile $(BUILD_PROFILE) --package g3proxy-ftp

override_dh_auto_install:
	install -m 755 -D target/$(BUILD_PROFILE)/g3proxy debian/tmp/usr/bin/g3proxy
	install -m 755 -D target/$(BUILD_PROFILE)/g3proxy-ctl debian/tmp/usr/bin/g3proxy-ctl
	install -m 755 -D target/$(BUILD_PROFILE)/g3proxy-ftp debian/tmp/usr/bin/g3proxy-ftp
	install -m 755 -D target/$(BUILD_PROFILE)/g3proxy-lua debian/tmp/usr/bin/g3proxy-lua

override_dh_installchangelogs:
	dh_installchangelogs $(PACKAGE_NAME)/CHANGELOG
